﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace EveryDayMatters

{
    public partial class Form1 : Form
    {
        private System.Windows.Forms.Timer timer;
        private Random random;
        private int clickCount = 0; // 记录点击次数
        private PictureBox pictureBox1;
        private PictureBox pictureBox2;
        private PictureBox pictureBox3;
        private Label timeLabel;
        private DateTime startTime;
        public Form1()
        {
            InitializeComponent();
            InitializeCustomComponents();
        }
        private void InitializeCustomComponents()
        {
            // 初始化爱心按钮
            Button loveButton = new Button
            {
                Text = "❤",
                Font = new Font("Arial", 24, FontStyle.Bold),
                ForeColor = Color.Red,
                BackColor = Color.Transparent,
                FlatStyle = FlatStyle.Flat,
                Size = new Size(400, 400),
                Location = new Point(1200, 1100),
                Cursor = Cursors.Hand
            };
            loveButton.MouseEnter += LoveButton_MouseEnter;
            loveButton.MouseLeave += LoveButton_MouseLeave;
            loveButton.Click += LoveButton_Click;
            Controls.Add(loveButton);
            // 初始化定时器
            timer = new System.Windows.Forms.Timer { Interval = 1000 };
            timer.Tick += Timer_Tick;
            // 初始化随机数生成器
            random = new Random();
            // 初始化图片框
            pictureBox1 = new PictureBox
            {
                Size = new Size(800, 900),
                Location = new Point(100, 130),
                Visible = false,
                SizeMode = PictureBoxSizeMode.Zoom // 保持图片的纵横比
            };
            pictureBox1.Image =
            Image.FromFile("D:\\CSharp2024\\Properties\\EveryDayMatters.png"); // 背景图片路径
            Controls.Add(pictureBox1);

            pictureBox2 = new PictureBox
            {
                Size = new Size(800, 900),
                Location = new Point(1000, 130),
                Visible = false,
                SizeMode = PictureBoxSizeMode.Zoom // 保持图片的纵横比
            };
            pictureBox2.Image =
            Image.FromFile("D:\\CSharp2024\\Properties\\1.jpg"); // 背景图片路径
            Controls.Add(pictureBox2);

            pictureBox3 = new PictureBox
            {
                Size = new Size(800, 900),
                Location = new Point(1900, 130),
                Visible = false,
                SizeMode = PictureBoxSizeMode.Zoom // 保持图片的纵横比
            };
            pictureBox3.Image =
            Image.FromFile("D:\\CSharp2024\\Properties\\3.jpg"); // 背景图片路径
            Controls.Add(pictureBox3);
            // 初始化时间标签
            timeLabel = new Label
            {
                AutoSize = true,
                Font = new Font("Arial", 14, FontStyle.Bold),
                ForeColor = Color.Black,
                Location = new Point(1100, 1050),
                Visible = false
            };
            Controls.Add(timeLabel);
            // 记录开始时间
            DateTime startTime = new DateTime(2023, 10, 12, 5, 20, 0);
        }
        private void LoveButton_MouseEnter(object sender, EventArgs e)
        {
            ((Button)sender).ForeColor = Color.Pink;
            timer.Start();
        }
        private void LoveButton_MouseLeave(object sender, EventArgs e)
        {
            ((Button)sender).ForeColor = Color.Red;
            timer.Stop();
        }
        private void Timer_Tick(object sender, EventArgs e)
        {
            // 创建泡泡
            PictureBox bubble = new PictureBox
            {
                Size = new Size(20, 20),
                BackColor = Color.LightPink,
                Location = new Point(random.Next(this.ClientSize.Width),
 this.ClientSize.Height)
            };
            Controls.Add(bubble);
            bubble.BringToFront();
            // 动画效果
            System.Windows.Forms.Timer bubbleTimer = new System.Windows.Forms.Timer { Interval = 10 };
            bubbleTimer.Tick += (s, ev) =>
            {
                bubble.Top -= 5;
                if (bubble.Top < 0)
                {
                    Controls.Remove(bubble);
                    bubbleTimer.Stop();
                }
            };
            bubbleTimer.Start();

        }
        private void LoveButton_Click(object sender, EventArgs e)
        {
            if (clickCount == 1)
            {
                // 显示背景图片
                pictureBox1.Visible = true;
            }
            clickCount++;
            if (clickCount == 2)
            {
                // 显示背景图片
                pictureBox2.Visible = true;
            }
            if (clickCount == 3)
            {
                // 显示背景图片和时间
                pictureBox3.Visible = true;
                timeLabel.Visible = true;
                // 计算时间差
                TimeSpan elapsedTime = DateTime.Now - startTime;
                timeLabel.Text = $"在一起的时间: {elapsedTime.TotalMilliseconds} 毫秒";
            }
        }
    }
}